package com.example.wisdomclassroomapi.facade.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.Getter;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

@Data
public class RequestAuthenticationDetails extends WebAuthenticationDetails {

    private final String username;

    private final String password;

    private final String captcha;

    private final String captchaId;

    public RequestAuthenticationDetails(HttpServletRequest request) throws IOException {
        super(request);

        Map<String, String> params = new ObjectMapper().readValue(request.getInputStream(), Map.class);
        this.username = params.get("username");
        this.password = params.get("password");
        this.captchaId = params.get("captchaId");
        this.captcha = params.get("captcha");
    }
}
